home *** CD-ROM | disk | FTP | other *** search
- #include "lib.h"
-
- /*
- * strstr - find first occurrence of wanted in s
- */
- #ifdef NULL
- #undef NULL
- #endif
-
- #define NULL 0
-
- char * /* found string, or NULL if none */
- strstr(s, wanted)
- _CONST char *s;
- _CONST char *wanted;
- {
- register _CONST char *scan;
- register _SIZET len;
- register char firstc;
- #ifndef __STDC__ /* for __STDC__ pick up proto from <std.h> */
- extern int strcmp();
- extern _SIZET strlen();
- #endif
-
- /*
- * The odd placement of the two tests is so "" is findable.
- * Also, we inline the first char for speed.
- * The ++ on scan has been moved down for optimization.
- */
- firstc = *wanted;
- len = strlen(wanted);
- for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
- if (*scan++ == '\0')
- return(NULL);
- return((char *)scan);
- }
-